package com.example.demo.controller;

import com.example.demo.entity.Student;
import com.example.demo.service.Impl.StudentServiceImpl;
import com.example.demo.vo.ResponseVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags = "学生管理相关接口")
@RestController //@Controller + @ResponseBody
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentServiceImpl studentService;// 不用autowired是因为装配容器时有先后顺序，autowired自动装配发现组件未初始化而报错，构造器式会在装配时查找引用并初始化

    @ApiOperation(value = "获取全部学生-普通",produces = "application/json")
    @ApiImplicitParams({
        @ApiImplicitParam(name="id",value="学生id",required = true,dataType = "String",defaultValue = "")
    })
    @GetMapping("/getOne1/{id}")
    public ResponseVo<Student> selectByPrimaryKey1(
        @PathVariable
        @ApiParam(name="id",value="学生id",required = true)
        @RequestParam("id")
        Long id
    ) {
        return studentService.selectByPrimaryKey(id);
    }

    @ApiOperation(value = "获取全部学生-query变更",produces = "application/json")
    @ApiImplicitParams({
        @ApiImplicitParam(name="studentId",value="学生id",required = true,dataType = "String",defaultValue = "")
    })
    @GetMapping("/getOne2")
    public ResponseVo<Student> selectByPrimaryKey2(@RequestParam("studentId") Long id) {
        return studentService.selectByPrimaryKey(id);
    }

    @ApiOperation(value = "获取全部学生-默认值",produces = "application/json")
    @ApiImplicitParams({
        @ApiImplicitParam(name="id",value="学生id",required = true,dataType = "String",defaultValue = "1003")
    })
    @GetMapping("/getOne3")
    public ResponseVo<Student> selectByPrimaryKey3(@RequestParam(defaultValue = "1003") Long id) {
        return studentService.selectByPrimaryKey(id);
    }

    @ApiOperation(value = "获取全部学生-map获取",produces = "application/json")
    @ApiImplicitParams({
        @ApiImplicitParam(name="id",value="学生id",required = true,dataType = "String",defaultValue = "")
    })
    @GetMapping("/getOne4")
    public ResponseVo<Student> selectByPrimaryKey4(@RequestParam(required = false) Map map) {
        return studentService.selectByPrimaryKey(Long.parseLong(map.get("id").toString()));
    }

    @ApiOperation(value = "获取全部学生-post",produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="学生id",required = true,dataType = "String",defaultValue = "")
    })
    @GetMapping("/getOne5")
    public ResponseVo<Student> selectByPrimaryKey5(@RequestBody Long id) {
        return studentService.selectByPrimaryKey(id);
    }
}
